<?php
/*
* Plugin Name: Shortcodes for discrimination
* Plugin URI: http://aaron.jorb.in
* Description: Adds shortcodes to make content only viewable by users with a spcific capability, or only by non logged in users
* Version: 0.0
* Author: Aaron Jorbin
* Author URI: http://aaron.jorb.in
*/
/*
 * 		Copywrite 2010 Aaron Jorbin (aaron@jorb.in)
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without weven the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

class jorbin_user_shortcodes{

    /**
     * Add our Init action, which is where the real work begins
     */
    function __construct(){
	add_action( 'init', array( $this , 'init') );
    }

    /**
     * Starter up
     *
     */
    function init(){
	add_shortcode('user', array( $this, 'logged_in_shortcode') );
	add_shortcode('notuser', array( $this, 'not_logged_in_shortcode') );
    }

/**
 *  Shortcode Callback to return shortcode contents only for users with a certain capability
 *
 */
    function logged_in_shortcode($atts, $content){
	extract( shortcode_atts(
	    array('capability' => 'read',)
	    , $atts));

	 if ( current_user_can ($capability)  )
		return $content;
	 else
		return '';

    }

    /**
     * Shortcode Callback to return shortcode contents only for non-logged in users
     *
     */

    function not_logged_in_shortcode($atts, $content){
	
	if ( is_user_logged_in() )
		return '';
	else
		return $content;

    }

}

$jorbin_user_shortcodes = new jorbin_user_shortcodes();

